package com.example.twoDataSource.config;

import com.example.twoDataSource.context.DataSourceContextHolder;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

public class DynamicDataSource extends AbstractRoutingDataSource
{
    
    private static Logger log = LogManager.getLogger(DynamicDataSource.class);
    
    @Override
    protected Object determineCurrentLookupKey()
    {
        log.debug("数据源为{}", DataSourceContextHolder.getDB());
        
        return DataSourceContextHolder.getDB();
    }
    
}
